<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

require_once './_AddinLibraries/database_driver.php';

function add_class($id, $program, $startYear, $endYear, $description) {
    select_itec_database();
    $sql = db_query("call sp_AddClass('".$id."','".$program."','".$startYear."','".$endYear."','".$description."')");
    $result = $sql->fetchAssoc();
    select_drupal_database();
    
    return $result['result'];
}

function get_program_list() {
    select_itec_database();
    $result = array();
    $sql = db_query("call sp_GetListOfPrograms()");
    
    $i = 0;
    while($temp = $sql->fetchAssoc()) {
        if($temp == null)
            break;
        $result[] = $temp['programid'];
    }
    
    select_drupal_database();
    return $result;
}
function program_list_query() {
    select_itec_database();
    $pro  = array();
    $sql = db_query("SELECT programID FROM program");
    while ($erg = $sql->fetchAssoc()) {
        if ($erg == NULL)
            break;
        $pro[] = $erg['programid'];
    };
    select_drupal_database();
    return $pro;
}
function get_degree_from_program($program) {
    select_itec_database();
    $sql = db_query("call sp_GetDegreeByProgram('".$program."')");
    $result = $sql->fetchAssoc();
    select_drupal_database();
    
    return $result['name'];
}

function update_class($id, $program, $startY, $endY, $des){
    select_itec_database();
    $sql = db_query("call sp_UpdateClassInfo('".$id."','".$program."','".$startY."','".$endY."','".$des."')");
    $result = $sql->fetchAssoc();
    
    select_drupal_database();
    return $result['result'];
}

function get_teaching_class_status_list(){
    select_itec_database();
    $status = array();
    $sql = db_query("select description from teaching_class_status");
    
    while ($erg = $sql->fetchAssoc()) {
        if ($erg == NULL)
            break;
        $status[] = $erg['description'];
    };
    
    select_drupal_database();
    return $status;
}

function get_class_info($id)
{
    select_itec_database();
    $sql = db_query("call sp_GetFullClassInfo('".$id."')");
    $erg = $sql->fetchAssoc();
    select_drupal_database();
    
    return $erg;
}
?>
